# 应用名称
APP_NAME=formflow

# 默认动作
.PHONY: all
all: build

# 构建前端
.PHONY: build-frontend
build-frontend:
	@echo "构建前端..."
	cd frontend && npm run build

# 准备嵌入静态文件
.PHONY: prepare-embed
prepare-embed:
	@echo "准备嵌入静态文件..."
	@mkdir -p backend/cmd/web
	@cp -r backend/web/* backend/cmd/web/ || echo "前端文件不存在，请先构建前端"

# 编译后端
.PHONY: build-backend
build-backend: prepare-embed
	@echo "构建后端..."
	cd backend && go build -o ../bin/$(APP_NAME) ./cmd

# 完整构建（前端+后端）
.PHONY: build
build: build-frontend build-backend
	@echo "构建完成"

# 清理
.PHONY: clean
clean:
	@echo "清理..."
	@rm -rf bin/
	@rm -rf backend/cmd/web/
	@echo "清理完成"

# 运行（开发模式）
.PHONY: run
run:
	@echo "启动应用..."
	@./bin/$(APP_NAME)

# 帮助
.PHONY: help
help:
	@echo "可用命令:"
	@echo "  make build         - 构建前端和后端"
	@echo "  make build-frontend - 仅构建前端"
	@echo "  make build-backend  - 仅构建后端"
	@echo "  make run           - 运行应用"
	@echo "  make clean         - 清理构建产物"
	@echo "  make help          - 显示帮助信息"